/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.apache.jackrabbit.j2ee;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 *
 * @author admin
 */
public class FileHandleFilter implements Filter {

  private FilterConfig filterConfig = null;

  public void init(FilterConfig filterConfig)
          throws ServletException {
    this.filterConfig = filterConfig;
  }

  public void destroy() {
    this.filterConfig = null;
  }

  public void doFilter(ServletRequest request,
          ServletResponse response, FilterChain chain)
          throws IOException, ServletException {
    if (filterConfig == null) {
      return;
    }
    if (!request.getContentType().equalsIgnoreCase("mulitpart/form-data")) {
      chain.doFilter(request, response);

    } else {
        System.out.println("forwarding...");
       filterConfig.getServletContext().getRequestDispatcher("/my/upload_server.jsp").forward(request, response);
            return;

    }

  }
}
